
function PlayerView(_player, _map){
	var MapModule = require('ti.map');
	
	var AnnotationType = require('ui/model/constants/AnnotationType');
	
	var Player = require('ui/model/Player');
	var TroopView = require('ui/common/TroopView');
	var TankView = require('ui/common/TankView');
	var MotorcycleView = require('ui/common/MotorcycleView');
	
	
	var self = MapModule.createAnnotation({
		type: null, //AnnotationType.ANNOTATION_PLAYER, //Tipo de Anotacion
		player: _player, 	//Jugador Propietario 
		map: _map, 			//Mapa
		troops:[],			//Array de Tropas ubicadas en el mapa 
				
		//Propiedades MapModule.Annotation
		title: _player.name + ' (' + _player.id + ')',
		//subtitle: _player.latitude + ';' + _player.longitude,
		subtitle: _player.getDetails(),		
		latitude: _player.latitude,
		longitude: _player.longitude,
		//image: '/images/user.png',
		
		createTroop: function(troopType){
			
			Ti.App.controller.player.createTroop(troopType);
		},
		
		addTroop: function(troop){
			var troopView = null;
			
			//Crea la vista de la nueva tropa	
			switch(troop.type) {
    			case AnnotationType.ANNOTATION_TANK:
    			
    				troopView = new TankView(troop, this.map);
  	      			break;
  	      			
    			case AnnotationType.ANNOTATION_MOTORCYCLE:
    			
    				troopView = new MotorcycleView(troop, this.map);
        			break;
        			
    			default:
    			
    				troopView = new TroopView(troop, this.map);
			}
							
			if (troopView!= null){
				
				
				//Agrega la Tropa al array de tropas
				this.troops[this.troops.length] = troopView;
				this.map.addAnnotation(troopView);
			}
			
		},
		
		getDetails: function(){
			if (this.player!= null){
				return this.player.getDetails();
			}
			else {
				return '';
			}
		},
		
		refresh: function(){
			if (this.player!= null){
				this.subtitle = this.player.getDetails();
			}
			else {
				return '';
			}
		}
	});
	
	
	self.type = _player.type;

	if (_player.enemy){
		self.image='/images/playerEnemy.png';	
	}
	else{
		self.image='/images/player.png';
	}
	
	
	//Relaciona el jugador con la vista
	_player.view = self;
	_player.latitude = self.latitude;
	_player.longitude = self.longitude;
	
	return self;
	
};

module.exports = PlayerView; 
